#!/usr/bin/python

# This script basically replaces blank spaces by underline characters in script IDs in a
# log file, so that we can use the analyser script properly. For naming pattern, see
# comments on script count-doublebr-precision.

import sys

inputFile = open(sys.argv[1]);

while True:
    line = inputFile.readline();
    if not line:
        break;

    if line[:8] == "return: ":
        prefix = line[:8];
        line = line[8:];
        line = line.replace(" ", "_");
        line = prefix + line;

    elif line[:6] == "stop: ":
        prefix = line[:6];
        line = line[6:];
        line = line.replace(" ", "_");
        line = prefix + line;

    elif line[:11] == "iteration: ":
        prefix = line[:11];
        line = line[11:];
        sufix = line.split(" pc=", 1)[-1];
        sufix = " pc=" + sufix;
        line = line.split(" pc=", 1)[0];
        line = line.replace(" ", "_");
        line = prefix + line + sufix;

    elif line[:13] == "first-guess: ":
        prefix = line[:13];
        line = line[13:];
        sufix = line.split(" pc=", 1)[-1];
        sufix = " pc=" + sufix;
        line = line.split(" pc=", 1)[0];
        line = line.replace(" ", "_");
        line = prefix + line + sufix;

    elif line[:14] == "second-guess: ":
        prefix = line[:14];
        line = line[14:];
        sufix = line.split(" pc=", 1)[-1];
        sufix = " pc=" + sufix;
        line = line.split(" pc=", 1)[0];
        line = line.replace(" ", "_");
        line = prefix + line + sufix;

    print(line),;
